package com.love.marriage.membershipConfiguration.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.membershipConfiguration.entity.MembershipConfiguration;
import com.love.marriage.membershipConfiguration.mapper.MembershipConfigurationMapper;
import com.love.marriage.membershipConfiguration.service.MembershipConfigurationService;
import com.love.marriage.membershipConfiguration.vo.MembershipConfigurationVo;
import com.love.marriage.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * description:  会员配置表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-12 23:29:12
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class MembershipConfigurationServiceImp extends ServiceImpl<MembershipConfigurationMapper, MembershipConfiguration> implements MembershipConfigurationService {

    private final MembershipConfigurationMapper membershipConfigurationMapper;

    @Override
    public Page<MembershipConfigurationVo> getPage(Long pageNum, Long pageSize, MembershipConfigurationVo membershipConfigurationVo) {
        Page<MembershipConfigurationVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return membershipConfigurationMapper.getPage(page, membershipConfigurationVo);
    }

    @Override
    public List<MembershipConfigurationVo> getList(MembershipConfigurationVo membershipConfigurationVo) {
        if (membershipConfigurationVo == null) {
            membershipConfigurationVo = new MembershipConfigurationVo();
        }
        membershipConfigurationVo.setStatus(true);
        return membershipConfigurationMapper.getList(membershipConfigurationVo);
    }

    @Override
    public MembershipConfigurationVo queryMembershipConfiguration(Long id) {
        return membershipConfigurationMapper.queryMembershipConfiguration(id);
    }

    @Override
    public MembershipConfigurationVo addMembershipConfiguration(MembershipConfigurationVo membershipConfigurationVo) {
        MembershipConfiguration membershipConfiguration = new MembershipConfiguration();
        BeanUtils.copyProperties(membershipConfigurationVo, membershipConfiguration);
        membershipConfigurationMapper.insert(membershipConfiguration);
        MembershipConfigurationVo res = new MembershipConfigurationVo();
        BeanUtils.copyProperties(membershipConfiguration, res);
        return res;
    }

    @Override
    public MembershipConfigurationVo updateMembershipConfiguration(MembershipConfigurationVo membershipConfigurationVo) {
        MembershipConfiguration membershipConfiguration = new MembershipConfiguration();
        BeanUtils.copyProperties(membershipConfigurationVo, membershipConfiguration);
        membershipConfigurationMapper.updateById(membershipConfiguration);
        return membershipConfigurationVo;
    }

    @Override
    public Boolean deleteMembershipConfiguration(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        membershipConfigurationMapper.deleteBatchIds(idArr);
        return true;
    }
}
